﻿@using DBMS.Models

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Database Structure</h2>
<h3>@ViewBag.Database.Name</h3>

<div>@Html.ActionLink("Edit Database", "EditDatabase", "Databases", new { databaseId = ViewBag.Database.Index.ToString() }, null)</div>

<div>@Html.ActionLink("Create New Table", "CreateTable", "Tables", new { databaseId = ViewBag.Database.Index.ToString(), databaseName = ViewBag.Database.Name}, null)</div>

<div>@Html.ActionLink("New Query", "Create", "Query", new { databaseId = ViewBag.Database.Index.ToString() }, null)</div>

<div>@Html.ActionLink("Relationships", "Relationships", "Databases", new { databaseId = ViewBag.Database.Index.ToString() }, null)</div>

@{ 
    if (ViewBag.Tables.Count > 0)
    {
        <table>
            <tbody>
                @{
                   foreach (Table table in ViewBag.Tables)
                   {  
                       <tr>
                            <td>
                                @table.Name
                            </td>
                            <td>
                                @Html.ActionLink("Browse", "BrowseTable", "Tables", new { databaseId = ViewBag.Database.Index.ToString(), tableId = table.Index }, null)
                                @Html.ActionLink("Structure", "Index", "Columns", new { databaseId = ViewBag.Database.Index.ToString(), tableId = table.Index }, null)
                                @Html.ActionLink("Rename", "EditTable", "Tables", new { databaseId = ViewBag.Database.Index.ToString(), tableId = table.Index }, null)
                                @Html.ActionLink("Drop", "DropTable", "Tables", new { databaseId = ViewBag.Database.Index.ToString(), tableId = table.Index }, null)
                            </td>
                       </tr>
                   }
                }
            </tbody>
        </table>
   }
   else
   {
        <div>This database doesn't contain any tables.</div>
   }
}